<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class AdminIndex extends MY_Controller {
	public function __construct(){
		parent::__construct();
		$this->isLogin();
		$this->load->model('Customer_model');
		$this->load->model('User_model');
		$this->load->model('AdminIndex_model');
	}
	public function index(){	
		$this->display('index/index.html');
	}
	//项目进度统计
	public function projectProgress(){
		$where=array();		
		$recordresult=$this->AdminIndex_model->pm_projectrecord_all($where);
		$count=array();
		$count['jiaji']=0;
		$count['xinjian']=0;
		$count['kaifa']=0;
		$count['dahui']=0;
		$count['wancheng']=0;
		foreach($recordresult as $key=>$value){
			if($value['status']==0){//新建
				$count['xinjian']++;
			}else if($value['status']==19||$value['status']==29||$value['status']==39){//打回
				$count['dahui']++;
			}else if($value['status']==3){//开发中
				$count['kaifa']++;
			}else if($value['status']==100){//完成
				$count['wancheng']++;
			}
			if(($value['status']!=19||$value['status']!=29||$value['status']!=39||$value['status']!=100)&&$value['isquick']==1){//在新建以及签字中的加急
				$count['jiaji']++;
			}
		}
		//查询每月的完成个数
		$year = date('Y');
		$yeararr = [];
		$month = [];
		for ($i=1; $i <=12 ; $i++) { 
			$yeararr[$i]=$year.'-'.$i;
			$data['date'][$i]='"'.$i.'月'.'"';
		}
		foreach($yeararr as $key => $value){
			$timestamp=strtotime($value);
			$start_time=date( 'Y-m-1 00:00:00',$timestamp );
			$mdays=date( 't', $timestamp );
			$end_time=date('Y-m-'.$mdays.'23:59:59',$timestamp );
			$month[$key]['start_time']=$start_time;
			$month[$key]['end_time']=$end_time;
		}
		foreach($month as $key => $value){
			$where=array();
			$where['status']=array('=',100);
			$where['addtime']=['between',strtotime($value["start_time"]),strtotime($value["end_time"])];
			$data['count'][$key]=$this->AdminIndex_model->pm_projectrecord_all_count($where);
		}
		$data['date'] = '['.implode(",", $data['date']).']';
		$data['count'] = '['.implode(",", $data['count']).']';
		//echo $this->db->last_query();
		$this->assign('count',$count);
		$this->assign('data',$data);
		$this->display('index/projectProgress.html');
	}
}
